using Box2D.Net.Collision.Shapes;
using Box2D.Net.Dynamics.Bodies;
using Box2D.Net.Dynamics.Fixtures;
using Box2D.Net.Dynamics.World;
using System.Numerics;

namespace Box2D.WorldTests
{
    public static class Box2DBug604World
    {
        public static World CreateWorld()
        {
            var gravity = new Vector2(0.0f, -10.0f);
            var world = new World(gravity);
            var chainShape = new ChainShape();

            Vector2[] vertices =
            {
                new Vector2(-5, 0),
                new Vector2(5, 0),
                new Vector2(5, 5),
                new Vector2(4, 1),
                new Vector2(-4, 1),
                new Vector2(-5, 5)
            };

            chainShape.CreateLoop(vertices);

            var groundFixtureDef = new FixtureDef();
            groundFixtureDef.Density = 0;
            groundFixtureDef.Shape = chainShape;

            var groundBodyDef = new BodyDef();
            groundBodyDef.Type = BodyType.Static;

            var groundBody = world.CreateBody(groundBodyDef);
            var groundBodyFixture = groundBody.CreateFixture(groundFixtureDef);

            var ballShape = new CircleShape();
            ballShape.Radius = 1;

            var ballFixtureDef = new FixtureDef();
            ballFixtureDef.Restitution = 0.75f;
            ballFixtureDef.Density = 1;
            ballFixtureDef.Shape = ballShape;

            var ballBodyDef = new BodyDef();
            ballBodyDef.Type = BodyType.Dynamic;
            ballBodyDef.Position = new Vector2(0, 10);

            var ball = world.CreateBody(ballBodyDef);
            var ballFixture = ball.CreateFixture(ballFixtureDef);

            ball.ApplyForceToCenter(new Vector2(-1000, -400), true);

            return world;
        }
    }
}